package com.jiepos.mpos.biz.code.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.jiepos.mpos.biz.code.service.AppAreaCdService;
import com.jiepos.mpos.common.entity.App_Area_CdEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;

/**
 * 
 * 
 * <p>标题: —— 地区代码表控制器</p>
 * <p>模块: 通用平台</p>
 * <p>版权: Copyright (c) 2017 江苏杰博实信息技术有限公司
 * @author 张学涛
 * @version 1.0
 * @since 2017年9月15日下午2:25:25
 * @history（历次修订内容、修订人、修订时间等）
 */
@Controller
@RequestMapping("areacd")
public class AppAreaCdController extends BaseController {

	@Autowired
	private AppAreaCdService appAreaCdService;
	
	/**
	 * 进入地区代码信息列表页面
	 * @param request
	 * @param response
	 * @param pagination
	 * @return
	 */
	@RequestMapping("/getAreaCdList.do")
	public ModelAndView getAreaCdList(HttpServletRequest request, HttpServletResponse response,
			Pagination pagination){
		ModelAndView model = new ModelAndView("/module/code/areacd/areacd_list");		
		return super.getDetail(request, response, model);		
	}
	
	/**
	 * 查询地区代码列表信息json数据
	 * @param request
	 * @param response
	 * @param pagination
	 * @param appAreaCdEntity
	 * @return
	 */
	@RequestMapping("/getAreaCdListJson.do")
	public @ResponseBody Map getAreaCdListJson(Pagination pagination,App_Area_CdEntity appAreaCdEntity){		
		return appAreaCdService.getAreaCdList(pagination, appAreaCdEntity);
	}
	
	/**
	 * 获取地区菜单树
	 * @return
	 */
	@RequestMapping("/getAreaTree.do")
	@ResponseBody
	public List<Map<String, Object>> getAreaTree(){
		return appAreaCdService.getAreaTree();
	}
	
	/**
	 * 进入地区代码信息详细页面
	 * @param request
	 * @param response
	 * @param pagination
	 * @param area_uuid
	 * @return
	 */
	@RequestMapping("/getAreaCdDetail.do")
	public ModelAndView getAreaCdDetail(HttpServletRequest request, HttpServletResponse response,
			Pagination pagination,String area_uuid) {
		ModelAndView model = new ModelAndView("/module/code/areacd/areacd_detail");
		Map appAreaCdEntity=appAreaCdService.getAreaCdById(area_uuid);		
		model.addObject("appAreaCdEntity", appAreaCdEntity);
		model.addObject("cdAndName", appAreaCdEntity.get("cdAndName"));
		return super.getDetail(request, response, model);
	}
	
	/**
	 * 保存地区代码
	 * @param request
	 * @param response
	 * @param appAreaCdEntity
	 * @return
	 */
	@RequestMapping("/saveAreaCd.do")
	public ModelAndView saveAreaCd(HttpServletRequest request, HttpServletResponse response,
			App_Area_CdEntity appAreaCdEntity) {
		appAreaCdService.saveAreaCd(appAreaCdEntity, super.getLoginUser(request, response));		
		Map map=super.getLoginUser(request, response);	
		return new ModelAndView(new RedirectView("getAreaCdList.do"), map);
	}
	
	/**
	 * 删除地区代码信息
	 * @param request
	 * @param response
	 * @param area_uuids
	 * @return
	 */
	@RequestMapping("/deleteAreaCdByIds.do")
	public ModelAndView deleteAreaCdByIds(HttpServletRequest request, HttpServletResponse response, String area_uuids) {
		appAreaCdService.deleteAreaCdByIds(area_uuids);		
		Map map=super.getLoginUser(request, response);  
		return new ModelAndView(new RedirectView("getAreaCdList.do"), map);
	}
	
	/**
	 * 校验地区代码
	 * @param appAreaCdEntity
	 * @return
	 */
	@RequestMapping("/checkAreaCd.do")
	public @ResponseBody String checkAreaCd(App_Area_CdEntity appAreaCdEntity){		
		return appAreaCdService.checkAreaCd(appAreaCdEntity);
	}
}
